package io.renren.modules.user.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.user.dao.UserinfoDao;
import io.renren.modules.user.entity.UserinfoEntity;
import io.renren.modules.user.service.UserinfoService;


@Service("userinfoService")
public class UserinfoServiceImpl extends ServiceImpl<UserinfoDao, UserinfoEntity> implements UserinfoService {
    // 调用自己的dao层需要注入依赖
    @Autowired
    private UserinfoDao userinfoDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String username =(String) params.get("key");//模糊查询
        boolean blank = StringUtils.isBlank(username);
        QueryWrapper<UserinfoEntity> queryWrapper;
        if(blank){
            queryWrapper = new QueryWrapper<UserinfoEntity>();
        }else{
            queryWrapper = new QueryWrapper<UserinfoEntity>().like("user_name",username);
        }
        IPage<UserinfoEntity> page = this.page(
                new Query<UserinfoEntity>().getPage(params),//分页工具
                queryWrapper
//                new QueryWrapper<UserinfoEntity>().like("user_name",username)
        );

        return new PageUtils(page);
    }

    @Override
    public void selectByUser(String username,Page page) {
        userinfoDao.selectByUser(username,page);
    }

    @Override
    public List<UserinfoEntity> listUserInfo() {
       return userinfoDao.listUserInfo();
    }

    @Override
    public UserinfoEntity selectUserById(Integer userNo) {
        return userinfoDao.selectUserById(userNo);
    }

    @Override
    public int insertUser(UserinfoEntity userinfoEntity) {
        return userinfoDao.insertUser(userinfoEntity);
    }

}